<?php

include "../../../lib/start.php";
check_session();
check_permission(DOC_PERM);

if(!isset($_REQUEST['offset']))
    $offset = 0;
else
    $offset = $_REQUEST['offset'];

$limit = 10;

$sel_docs = "SELECT documents.*, anni.descrizione, progetti.nome AS proj FROM documents, document_types, anni, progetti WHERE documents.progetto = progetti.id_progetto AND documents.doc_type = document_types.id AND document_types.id = 3 AND anni.id_anno = documents.anno_scolastico AND owner = ".$_SESSION['__user__']->getUid()." ORDER BY anno_scolastico DESC, data_upload DESC ";

if(!isset($_REQUEST['second'])){
    $res_docs = $db->execute($sel_docs);
    //print $sel_links;
    $count = $res_docs->num_rows;
    //print $count;
    $_SESSION['count_docs'] = $count;
}
else{
    $sel_docs .= " LIMIT $limit OFFSET $offset";
    $res_docs = $db->execute($sel_docs);
}

if($offset == 0)
    $page = 1;
else
    $page = ($offset / $limit) + 1;

$pagine = ceil($_SESSION['count_docs'] / $limit);
if($pagine < 1)
    $pagine = 1;

// dati per la paginazione (navigate.php)
$colspan = 4;
$link = basename($_SERVER['PHP_SELF']);
$count_name = "count_docs";

include "doc_progetto.html.php";

?>